package com.spring.provideronetest.test;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.stream.LongStream;

/**
 * @auther zhangxiangtao
 * @date 2021/1/7
 */
public class LeetCode {
	public static void main(String[] args) {//psvm
		Logger logger = LoggerFactory.getLogger(LeetCode.class);
		Girl 女朋友 = new Girl();

		logger.info(女朋友.toString());

		new ThreadLocal<String>().set("小傅哥");
//		new Thread(()->{},"a").start();
//		int i = 0;
//		System.out.println(i);

//		Function<String,String> function = (str)->{return str+"a";};
//		System.out.println(function.apply("asd"));//sout,或者变量下面的.sout
//
//			sum1();
//		int[] nums ={1,2,3};
//		ReentrantLock

//		int num =10;
//		num = num << 1;
//		System.out.println(num);
//		num = num >>> 2;
//		System.out.println(num);
		Colour colour = Colour.RED;
		switch (colour){
			case RED:
				System.out.println(Colour.RED.value);
				break;
			case YELLOW:
				System.out.println(Colour.YELLOW);
				break;
		}
	}

	public enum Colour{
		RED("zhang","jian"),YELLOW("w","s");

		Colour(String key,String value) {
			this.key = key;
			this.value = value;
		}

		private String key;
		private String value;

		public String getKey() {
			return key;
		}

		public void setValue(String value) {
			this.value = value;
		}

		public String getValue() {
			return value;
		}

		public void setKey(String key) {
			this.key = key;
		}
	}


	public static void sum1() throws ExecutionException, InterruptedException {
		Long statr =1L;
		Long end = 10000L;
		long time1 = System.currentTimeMillis();

		ForkJoinPool pool = new ForkJoinPool();
		ForkJoinTask<Long> fork = new ForkJoinTest(statr,end);
		ForkJoinTask<Long> submit = pool.submit(fork);
		Long num = submit.get();
		long time2 = System.currentTimeMillis();
		System.out.println(num+"时长为："+(time2-time1));
	}

	public static void sum2() {
		Long num =0L;
		long time1 = System.currentTimeMillis();
		for(Long i=1L;i<10_0000_0000L;i++){
			num+=i;
		}
		long time2 = System.currentTimeMillis();
		System.out.println(num+"时长为："+(time2-time1));
	}

	public static void sum3() {
		Long num =0L;
		long time1 = System.currentTimeMillis();
		num = LongStream.rangeClosed(0L,10_0000_0000L).parallel().reduce(0,Long::sum);
		long time2 = System.currentTimeMillis();
		System.out.println(num+"时长为："+(time2-time1));
	}
//	public List<List<String>> partition(String s){
//		int len = s.length();
//		List<List<String>> res = new ArrayList<>();
//		if (len == 0) {
//			return res;
//		}
//
//		// 预处理
//		// 状态：dp[i][j] 表示 s[i][j] 是否是回文
//		boolean dp[][] =new boolean[len][len];
//		// 状态转移方程：在 s[i] == s[j] 的时候，dp[i][j] 参考 dp[i + 1][j - 1]
//		for (int right=0;right < len;right++){
//			for (int left=0;left < right;left++){
//				if(s.charAt(left)== s.charAt(right) && (right-left<2 || dp[left+1][right-1])){
//					dp[left][right]=true;
//				}
//				dp[left][right]=false;
//			}
//		}
//
//
//		return res;
//	}
}

class Lazys{
	private volatile static Lazys lazys = null;

	Lazys(){}

	public static Lazys getInstance(){
		if(lazys == null){
			synchronized (Lazys.class){
				if(lazys == null){
					lazys = new Lazys();
				}
			}
		}
		return lazys;
	}
}
